﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.IManager;
using Business.Manager;
using Entity;
using System.Data;

namespace OnlinePayment.Admin
{
    public partial class AnnoucementList : System.Web.UI.Page
    {
        AnnouncementManager announcementManager = new AnnouncementManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!Page.IsPostBack)
            {
                //if (Session["username"] != null)
                //{
                   // Response.Write("<script language='javascript'>alert('非法操作，请先登录！');location.href = 'admin_login.aspx';</script>");
               // }
                //else
                //{
                    BindArticle();
               // }
            }
        }
        private void BindArticle()
        {
            GV_article.DataSource = announcementManager.getAnnouncements();
            if (GV_article.DataSource != null)
            {
                GV_article.DataBind();
            }
            
        }
        protected void GV_article_RowDataBound(object sender, GridViewRowEventArgs e)
        {

        }

        protected void GV_article_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
             int id = Convert.ToInt32(this.GV_article.Rows[e.RowIndex].Cells[0].Text);
             if (announcementManager.delAnnouncements(id))
             {
                 Response.Write("<script language='javascript'>alert('删除成功！');location.href = 'javascript:history.go(-1)';</script>");
             }
             else
             {
                 Response.Write("<script language='javascript'>alert('删除失败！');location.href = 'javascript:history.go(-1)';</script>");
             }
        }
        protected void GV_article_RowEditing(object sender, GridViewEditEventArgs e)
        {
            string id = this.GV_article.Rows[e.NewEditIndex].Cells[0].Text;
            Response.Redirect("AnnouncementEdit.aspx?id=" + id);
        }
        protected void GV_article_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

        }

        protected void DlPage_Init(object sender, EventArgs e)//DlPage就是分页中的下拉列表框
        {
            DropDownList list = (DropDownList)sender;
            for (int i = 1, j = GV_article.PageCount; i <= j; i++)
            {
                list.Items.Add(new ListItem(i.ToString()));
            }
            list.SelectedIndex = GV_article.PageIndex;
        }
        protected void DlPage_SelectedIndexChanged(object sender, EventArgs e)//DlPage就是分页中的下拉列表框
        {
            DropDownList list = (DropDownList)sender;
            GV_article.PageIndex = list.SelectedIndex;
            BindArticle();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {

            GV_article.DataSource = announcementManager.selectArcticle(txtKey.Text,ddlSearch.SelectedValue); 
            if (GV_article.DataSource != null)
            {
                GV_article.DataBind();
            }
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("PostAnnouncement.aspx");
        }
    }
}